package jsyf.oa.web.report;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import jsyf.com.util.BaseUtils;
import jsyf.com.util.ResponseUtils;
import jsyf.oa.facade.system.SignInFacade;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * Created by WHH-PC on 2018/2/1.
 */
@Api(value = "考勤报表接口", description = "考勤报表接口")
@Controller
@RequestMapping("/reportSignIn")
public class SignInReportController {

    @Resource
    private  SignInFacade signInFacade;

    @RequestMapping(value = "/getSignInList.json", method = RequestMethod.POST)
    @ApiOperation(
            value = "某个月考勤列表",
            notes = "某个月考勤列表",
            httpMethod = "POST",
            produces = MediaType.APPLICATION_JSON_VALUE)
    public void getSignInList(HttpServletRequest request, HttpServletResponse response, @RequestBody String jsonData) {
        JSONObject jsonObject = JSON.parseObject(jsonData);
        List<JSONObject> records = signInFacade.getSignInList(jsonObject);
        ResponseUtils.putJsonResponse(response, BaseUtils.succsessArrRespond(records));
    }

    @RequestMapping(value = "/getSignInByUserId.json", method = RequestMethod.POST)
    @ApiOperation(
            value = "获取某人某天是否签到、某个月的考勤汇总",
            notes = "获取某人某天是否签到、某个月的考勤汇总",
            httpMethod = "POST",
            produces = MediaType.APPLICATION_JSON_VALUE)
    public void getSignInByUserId(HttpServletRequest request, HttpServletResponse response, @RequestBody String jsonData) {
        JSONObject jsonObject = JSON.parseObject(jsonData);
        JSONObject json = signInFacade.getSignInByUserId(jsonObject);
        ResponseUtils.putJsonResponse(response, BaseUtils.succsessObjRespond(json));
    }

    @RequestMapping(value = "/getSignInRegionList.json", method = RequestMethod.POST)
    @ApiOperation(
            value = "获取大区经理考勤列表",
            httpMethod = "POST",
            produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParam(name = "jsonData", value = "{userId:\"2017121622414541840A353F976E47E0\",signInMonth:\"2018-02\"}", dataType = "String", paramType = "body")
    public void getSignInRegionList(HttpServletRequest request, HttpServletResponse response, @RequestBody String jsonData) {
        JSONObject jsonObject = JSON.parseObject(jsonData);
        List<JSONObject> list = signInFacade.getSignInRegionList(jsonObject);
        ResponseUtils.putJsonResponse(response, BaseUtils.succsessArrRespond(list));
    }

    @RequestMapping(value = "/getSignInSupportRegionList.json", method = RequestMethod.POST)
    @ApiOperation(
            value = "获取区域支持考勤列表",
            httpMethod = "POST",
            produces = MediaType.APPLICATION_JSON_VALUE)
    public void getSignInSupportRegionList(HttpServletRequest request, HttpServletResponse response, @RequestBody String jsonData) {
        JSONObject jsonObject = JSON.parseObject(jsonData);
        List<JSONObject> list = signInFacade.getSignInSupportRegionList(jsonObject);
        ResponseUtils.putJsonResponse(response, BaseUtils.succsessArrRespond(list));
    }

    @RequestMapping(value = "/getSignInSalerManagerList.json", method = RequestMethod.POST)
    @ApiOperation(
            value = "获取部门当天考勤汇总",
            httpMethod = "POST",
            produces = MediaType.APPLICATION_JSON_VALUE)
    public void getSignInSalerManagerList(HttpServletRequest request, HttpServletResponse response, @RequestBody String jsonData) {
        JSONObject jsonObject = JSON.parseObject(jsonData);
        List<JSONObject> list = signInFacade.getSignInSalerManagerList(jsonObject);
        ResponseUtils.putJsonResponse(response, BaseUtils.succsessArrRespond(list));
    }

    @RequestMapping(value = "/getSignInCompanyManagerList.json", method = RequestMethod.POST)
    @ApiOperation(
            value = "获取公司考勤汇总",
            httpMethod = "POST",
            produces = MediaType.APPLICATION_JSON_VALUE)
    public void getSignInCompanyManagerList(HttpServletRequest request, HttpServletResponse response, @RequestBody String jsonData) {
        JSONObject jsonObject = JSON.parseObject(jsonData);
        List<JSONObject> list = signInFacade.getSignInCompanyManagerList(jsonObject);
        ResponseUtils.putJsonResponse(response, BaseUtils.succsessArrRespond(list));
    }

    @RequestMapping(value = "/getSignInDepartManagerList.json", method = RequestMethod.POST)
    @ApiOperation(
            value = "月份筛选部门考勤",
            httpMethod = "POST",
            produces = MediaType.APPLICATION_JSON_VALUE)
    public void getSignInDepartManagerList(HttpServletRequest request, HttpServletResponse response, @RequestBody String jsonData) {
        JSONObject jsonObject = JSON.parseObject(jsonData);
        List<JSONObject> list = signInFacade.getSignInDepartManagerList(jsonObject);
        ResponseUtils.putJsonResponse(response, BaseUtils.succsessArrRespond(list));
    }

    @RequestMapping(value = "/getSignInDepartDetail.json", method = RequestMethod.POST)
    @ApiOperation(
            value = "某个部门考勤",
            httpMethod = "POST",
            produces = MediaType.APPLICATION_JSON_VALUE)
    public void getSignInDepartDetail(HttpServletRequest request, HttpServletResponse response, @RequestBody String jsonData) {
        JSONObject jsonObject = JSON.parseObject(jsonData);
        List<JSONObject> list = signInFacade.getSignInDepartDetail(jsonObject);
        ResponseUtils.putJsonResponse(response, BaseUtils.succsessArrRespond(list));
    }

    @RequestMapping(value = "/getGotoSignIn.json", method = RequestMethod.POST)
    @ApiOperation(
            value = "获取考勤需要跳转的页面",
            httpMethod = "POST",
            produces = MediaType.APPLICATION_JSON_VALUE)
    public void getGotoSignIn(HttpServletRequest request, HttpServletResponse response, @RequestBody String jsonData) {
        JSONObject jsonObject = JSON.parseObject(jsonData);
        JSONObject json = signInFacade.getGotoSignIn(jsonObject);
        ResponseUtils.putJsonResponse(response, BaseUtils.succsessObjRespond(json));
    }
}
